package com.bootdo.app;


import com.bootdo.common.utils.AppR;
import com.bootdo.common.utils.MD5Utils;
import com.bootdo.common.utils.R;
import com.bootdo.staff.service.StaffMenuRoleService;
import com.bootdo.staff.service.StaffMenuService;
import com.bootdo.staff.service.StaffUserService;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("api/staff")
public class AppStaffController {

    @Autowired
    private StaffUserService staffUserService;
    @Autowired
    private StaffMenuService staffMenuService;
    @Autowired
    private StaffMenuRoleService staffMenuRoleService;

    /**
     * 登陆api
     * @param staffName
     * @param password
     * @return
     */
   @GetMapping("/login")
   @ResponseBody
   public AppR login(@RequestParam String staffName,@RequestParam String password){	 
       return staffUserService.login(staffName,password);

   }


    /**
     * 获取该用户可以访问的菜单
     * @param staffId
     * @return
     */
   @GetMapping("/menu")
   @ResponseBody
   public AppR getMenu(@RequestParam Long staffId){
       Map<String,Object> map = new HashMap<>();
       map.put("list",staffMenuService.getMenuByStaffId(staffId));
       return AppR.ok(map);
   }

    /**
     * 查看是否有权限
     * @param staffId
     * @param smenuId
     * @return
     */
   @GetMapping("/role")
   @ResponseBody
   public AppR getIsRole(@RequestParam Long staffId,@RequestParam Long smenuId){
       return staffMenuRoleService.getIsRole(staffId,smenuId);
   }
}
